|
|
|
|
|
|
|
Listing 23.4 TRANSPAR.ZIPCode for the TransparentPaint Procedure |
|
|
|
|
|
|
|
|
'*********************************************************************
' Paints a bitmap on a given surface using the surface backcolor
' everywhere lngMaskColor appears on the picSource bitmap
'*********************************************************************
Sub TransparentPaint(objDest As Object, picSource As StdPicture, _
lngX As Long, lngY As Long, ByVal lngMaskColor As Long)
'*****************************************************************
' This sub uses a bunch of variables, so let's declare and explain
' them in advance . . .
'*****************************************************************
Dim lngSrcDC As Long 'Source bitmap
Dim lngSaveDC As Long 'Copy of Source bitmap
Dim lngMaskDC As Long 'Monochrome Mask bitmap
Dim lngInvDC As Long 'Monochrome Inverse of Mask bitmap
Dim lngNewPicDC As Long 'Combination of Source & Background bmps
Dim bmpSource As BITMAP 'Description of the Source bitmap
Dim hResultBmp As Long 'Combination of source & background
Dim hSaveBmp As Long 'Copy of Source bitmap
Dim hMaskBmp As Long 'Monochrome Mask bitmap
Dim hInvBmp As Long 'Monochrome Inverse of Mask bitmap
Dim hSrcPrevBmp As Long 'Holds prev bitmap in source DC
Dim hSavePrevBmp As Long 'Holds prev bitmap in saved DC
Dim hDestPrevBmp As Long 'Holds prev bitmap in destination DC
Dim hMaskPrevBmp As Long 'Holds prev bitmap in the mask DC
Dim hInvPrevBmp As Long 'Holds prev bitmap in inverted mask DC
Dim lngOrigScaleMode& 'Holds the original ScaleMode
Dim lngOrigColor& 'Holds original backcolor from source DC
'*****************************************************************
' Set ScaleMode to pixels for Windows GDI
'*****************************************************************
lngOrigScaleMode = objDest.ScaleMode
objDest.ScaleMode = vbPixels
'*****************************************************************
' Load the source bitmap to get its width (bmpSource.bmWidth)
' and height (bmpSource.bmHeight)
'*****************************************************************
GetObject picSource, Len(bmpSource), bmpSource
'*****************************************************************
' Create compatible device contexts (DCs) to hold the temporary
' bitmaps used by this sub
'*****************************************************************
lngSrcDC = CreateCompatibleDC(objDest.hdc)
lngSaveDC = CreateCompatibleDC(objDest.hdc)
lngMaskDC = CreateCompatibleDC(objDest.hdc)
lngInvDC = CreateCompatibleDC(objDest.hdc)
lngNewPicDC = CreateCompatibleDC(objDest.hdc)
'*****************************************************************
' Create monochrome bitmaps for the mask-related bitmaps
'***************************************************************** |
|
|
|
|
|